package uk.ac.aber.paws.server.ownership;

import java.sql.*;

import uk.ac.aber.paws.server.config.ConfigManager;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 21st May 2012
 * 
 * GenericComputerInfoQuery.java
 * 
 * This class provides a method for obtaining IP and MAC address info for a 
 * given computer name. It deals with it using a connector class that is an 
 * implemented interface to suit the environment where this information is
 * available.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class GenericComputerInfoQuery {

	String computerName = null;
	String MACAddress = null;
	String IPAddress = null;
	
	Connection conn;

	public GenericComputerInfoQuery(String computerName) {
		
		this.computerName = computerName;
		
		Class ownershipConnector;
		
		try {
			ownershipConnector = Class.forName(ConfigManager.getProperty("app.db.ownership.connectorclass"));
			
			OwnershipQueryInterface gm = (OwnershipQueryInterface) ownershipConnector.newInstance();
			
			IPAddress = gm.getIPAddress(computerName);
			MACAddress = gm.getMACAddress(computerName);
			
		} 
		catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public String getMACAddress() {
		
		return MACAddress;
	}
	
	public String getIPAddress() {
		
		return IPAddress;
	}
}
